{% extends "base_worklist.html" %}
{% load work_custom_filters %}  
{%block title%}
İş İstesi
{%endblock%}
{%block content%}
<div id="filtrelemeler" style="margin-left: 80px;">
<table style="font-size: 11px; margin-bottom: 3px;">
    <tr>	
            <th>Onay Durumları :</th>
            <td {%ifequal xgoster "Onayli" %} style="color: black; background-color: #FFDD00;" {%endifequal%}><a href="/worklist/islistesi/?goster=Onayli&is_sahibi={{xis_sahibi}}">Onaylanmışlar</a>&nbsp;|</td>
	        <td {%ifequal xgoster "Bekleyenler" %} style="color: black; background-color: #FFDD00;" {%endifequal%}><a href="/worklist/islistesi/?goster=Bekleyenler&is_sahibi={{xis_sahibi}}">Bekleyenler</a>&nbsp;|</td>
            <td {%ifequal xgoster "Hepsi" %}  style="color: black; background-color: #FFDD00;" {%endifequal%}><a href="/worklist/islistesi/?goster=Hepsi&is_sahibi={{xis_sahibi}}">Hepsi&nbsp;</a></td>
    		<th>İş Atanan :</th>
    		<td{%ifequal xis_sahibi user.username %}  style="color: black; background-color: #FFDD00;" {%endifequal%}><a href="/worklist/islistesi/?goster={{xgoster}}&is_sahibi={{user.username}}">İşlerim</a>&nbsp;|</td>
    		<td{%ifequal xis_sahibi "Hepsi" %}  style="color: black; background-color: #FFDD00;" {%endifequal%}><a href="/worklist/islistesi/?goster={{xgoster}}&is_sahibi=Hepsi">Hepsi</a></td>
    		<th>Gösterilen kayıtlar :</th>
    		<td>{%if isset_paginator.has_previous%}<a href="/worklist/islistesi/?goster={{xgoster}}&is_sahibi={{xis_sahibi}}&sayfa=1">&#060;&#060;En Yeni</a>&nbsp;<a href="/worklist/islistesi/?goster={{xgoster}}&is_sahibi={{xis_sahibi}}&sayfa={{isset_paginator.previous_page_number}}">&#060;Daha Yeni</a>{%endif%}&nbsp;Toplam {{xtoplam}} kayıttan  {{xstartindex}}-{{xendindex}} arası {%if isset_paginator.has_next %}<a href="/worklist/islistesi/?goster={{xgoster}}&is_sahibi={{xis_sahibi}}&sayfa={{isset_paginator.next_page_number}}">Daha Eski&#062;</a>&nbsp;<a href="/worklist/islistesi/?goster={{xgoster}}&is_sahibi={{xis_sahibi}}&sayfa={{xsonsayfa}}">En Eski&#062;&#062;</a>{%endif%}</td><td><a href="/worklist/islistesi/?goster={{xgoster}}&is_sahibi={{xis_sahibi}}&sayfa=Hepsi" title="!!dikkat: bu işlem uzun sürebilir. lütfen bekleyiniz!!">(Hepsini Getir)</a></td>
   
    </tr>
</table>
	
    {% if perms.worklist.coklu_onay %}
    	<button type="button" onClick="openTonay();">Seçilenleri Onayla</button></td>
    {%endif%}
  
</div>
<div id="dt_example">
<div id="container"> 
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">

    <thead> 
    	<tr>
    		<th>İş Başl. Tarihi</th>
    		<th>İş İsteyen</th>
    		<th>İş İstenen Atölye</th>
    		<th>İş Türü</th>
    		<th>Açıklama</th>   
    		<th>Lokasyon</th>
    		<th>İşlem Durum</th>
    		<th>Süreç Bilgilendirme Notu</th>
    		<th>Planlanan Bitiş Tarihi</th>
    		<th>İş Sahibi</th>
    		<th>id</th>
    		<th>O</th>
    	</tr>
    </thead>
    <tbody>
    {% for isset in isset %}
     <tr  {% ifequal isset.onaylandi 1 %}class="gradeA"{%endifequal%}>  
     	
        <td>{{ isset.planlanan_baslangic_tarihi }}</td>
        <td>{{ isset.kullanici.first_name.capitalize|default_if_none:isset.kullanici}}&nbsp;{{isset.kullanici.last_name.capitalize}}</td>
        <td>{{ isset.atolye }}</td>
        <td>{{ isset.turu|default_if_none:".."}}</td>
        <td>{{ isset.aciklama|default_if_none:".."}}</td>
        <td>{{ isset.lokasyon|default_if_none:".."  }}</td>
        <td>{{ isset.islem_durum|default_if_none:".."   }}</td>
        <td><a href="/worklist/isistek/{{isset.id}}/duzenle/?goster={{xgoster}}&is_sahibi={{xis_sahibi}}">{{ isset.eknot|default_if_none:".."|dotsifempty }}</a></td>
        <td><a href="/worklist/isistek/{{isset.id}}/duzenle/?goster={{xgoster}}&is_sahibi={{xis_sahibi}}">{{ isset.planlanan_bitis_tarihi|default_if_none:".."|dotsifempty  }}</a></td>
        <td><a href="/worklist/isistek/{{isset.id}}/duzenle/?goster={{xgoster}}&is_sahibi={{xis_sahibi}}">{{ isset.onaylayan_kullanici|default_if_none:".."|dotsifempty   }}</a></td>
        <td>{{ isset.id }}</td>
       {% ifequal isset.onaylandi 1 %}
       	<td><img title="{{isset.onaylandi|default_if_none:"0"}}" src="/media/images/checked.gif"/></td>
       {% else %}
       	<td><img title="{{isset.onaylandi|default_if_none:"0"}}" src="/media/images/delete.png"/></td>
       	{%endifequal%}
     </tr>
    {% endfor %}
	</tbody>
</table>
</div>
</div>
</div>
{% endblock %}
{%block script%}
<link rel="stylesheet" title="currentStyle" type="text/css" href="/media/css/demo_page.css" /> 
<link rel="stylesheet" title="currentStyle" type="text/css" href="/media/css/demo_table.css" /> 
<link rel="stylesheet" title="currentStyle" type="text/css" href="/media/css/TableTools.css" /> 
<link rel="stylesheet" title="currentStyle" type="text/css" href="/media/css/jquery.tooltip.css" />
<script type="text/javascript" language="javascript" src="/media/js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" src="/media/js/jquery.tooltip.js"></script> 
<script type="text/javascript" charset="utf-8" src="/media/ZeroClipboard/ZeroClipboard.js"></script> 
<script type="text/javascript" charset="utf-8" src="/media/js/TableTools.js"></script>
<script type="text/javascript" charset="utf-8"> 
	$(document).ready(function() {
		/*
		 * First step is to create title attributes for the rows in the table
		 * This isn't needed if the required 'title' attribute is already set in the HTML in the
		 * DOM 
		 */
		 
		$('#example tbody tr').each( function() {
			var sTitle;
			var nTds = $('td', this);
			var sAck = $(nTds[4]).text();	
			sTitle =  sAck
			
			this.setAttribute( 'title', sTitle );
		} );
		
		/* Apply the tooltips */
		$('#example tbody tr[title]').tooltip( {
			"delay": 0,
			"track": true,
			"fade": 250
		} );

		$('#example tr').click( function() {
			if ( $(this).hasClass('row_selected') )
				$(this).removeClass('row_selected');
			else
				$(this).addClass('row_selected');
		} );

		//image title attr sorting
		jQuery.fn.dataTableExt.oSort['title-string-asc']  = function(a,b) {
			var x = a.match(/title="(.*?)"/)[1].toLowerCase();
			var y = b.match(/title="(.*?)"/)[1].toLowerCase();
			return ((x < y) ? -1 : ((x > y) ?  1 : 0));
		};
		
		jQuery.fn.dataTableExt.oSort['title-string-desc'] = function(a,b) {
			var x = a.match(/title="(.*?)"/)[1].toLowerCase();
			var y = b.match(/title="(.*?)"/)[1].toLowerCase();
			return ((x < y) ?  1 : ((x > y) ? -1 : 0));
		};
					$('#example').dataTable(
						   {
							  
							   "aaSorting": [[ 0, "desc" ]],
							   "sPaginationType": "full_numbers",
						  	  	"sScrollY": 400,
						  	  	"iDisplayLength": 50,
								"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "Hepsi"]],
								"bStateSave": true,
								"iCookieDuration":300,		
								"aoColumnDefs": [
								     			{"sWidth": "5%", "aTargets": [0,5,8,11]},
								     			{"sWidth": "10%", "aTargets": [1,2,3]},
								     			{"sWidth": "10%", "aTargets": [7,9]},
								     			{"sWidth": "40%", "aTargets": [6]},
								     			{"bVisible":false,"sWidth": "0%","aTargets":[10,4]},
								     			{"sType": "title-string","aTargets":[11]}
								     		],
								     														
								"oLanguage": {
								"sLengthMenu": "Sayfa başına _MENU_ kayıt gösteriliyor",
								"sZeroRecords": "Kriter Bulunamadı ",
								"sInfo": "Toplam _TOTAL_ kayıttan _START_ ile _END_ arası kayıtlar",
								"sInfoEmpty": "0 kayıt ",
								"sInfoFiltered": "(Toplam _MAX_ kayıttan filtrelenenler)"
								
							}
					
				}
				);
		
	} );
</script> 
<script type="text/javascript" charset="utf-8"> 
function fnGetSelected()
{
	var oTableLocal = $('#example').dataTable( );
	
	var aReturn = new Array();
	var aTrs = oTableLocal.fnGetNodes();
	
	for ( var i=0 ; i<aTrs.length ; i++ )
	{
		if ( $(aTrs[i]).hasClass('row_selected') )
		{
			
			aReturn.push( aTrs[i] );
		}
	}
	
	return aReturn;
	
}

function fnGetIdsOfSelectedRows(oSelectedRows) {
    var aRowIndexes = new Array();
    var aRowData = new Array();
    var aReturn = new Array();
    var xReturn;
    var AllValues;
    var oTableLocal = $('#example').dataTable( );
    aRowIndexes = oSelectedRows;    

    // The first 4 columns in my DataTable are id's and are hidden.
    // Column0 = CustomerId
    // Column1 = OrderId
    // Column2 = OrderDetailId
    // Column3 = StateId

    // Here I loop through the selected rows and create a
    // comma delimited array of id's that I will be sending
    // back to the server for processing.
    
    xReturn = '[';
    
    for(var i = 0; i < aRowIndexes.length; i++){
        // fnGetData is a built in function of the DataTable
        // I'm grabbing the data from rowindex "i"
        aRowData = oTableLocal.fnGetData(aRowIndexes[i]);

        // I'm just concatenating the values and storing them
        // in an array for each selected row.
        AllValues = aRowData[10];

		if (i>0)
		{
        	xReturn = xReturn + ',' +AllValues;
		}
		else
		{
			xReturn = xReturn + AllValues;
		}
            //alert(AllValues);
        
        aReturn.push(AllValues);
    }

    xReturn = xReturn + ']';
	//alert(xReturn);
    return xReturn;
}
function openTonay()
{
	var onaylist = fnGetIdsOfSelectedRows(fnGetSelected());
	//alert(onaylist);
	if (onaylist.length>2)
	{		
		window.location.href = "/worklist/islistesi/coklu_onayla/?goster={{xgoster}}&is_sahibi={{xis_sahibi}}&onaylist=" + onaylist;
	}
}
</script>


{% endblock%}